﻿using System;
using System.Configuration;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace Shuba.Data
{
	public class DBConnection
	{
        static Shuba.Framework.Encryption Encryption = new Shuba.Framework.Encryption();

        static string DBServer = ConfigurationManager.AppSettings["db.server"];
        static string DBName = ConfigurationManager.AppSettings["db.name"];
        static string DBUser = ConfigurationManager.AppSettings["db.user"];
        static string DBPass = Encryption.Decrypt(ConfigurationManager.AppSettings["db.pwd"]);

        static string cn = String.Format("Data Source = {0}; Initial Catalog = {1}; User Id = {2}; Password = {3}", DBServer, DBName, DBUser, DBPass);
        //static string cn = String.Format("Data Source = {0}; Initial Catalog = {1}; User Id = {2}; Password = {3}; Connect Timeout = 60", "10.194.15.65", "SPAWEB", "spa", "mrt@17Dspsp@");
        //static string cn = String.Format("Data Source = {0}; Initial Catalog = {1}; User Id = {2}; Password = {3}", "10.194.15.65", "SPAWEB", "spa", "mrt@17Dspsp@");

        static DbProviderFactory provider = DbProviderFactories.GetFactory("System.Data.SqlClient");

        public static Database CreateDatabase()
        {   
            return new GenericDatabase(cn, provider);
        }

        public static string ConnStr()
        {
            Shuba.Framework.Encryption Encryption = new Shuba.Framework.Encryption();

            string DBServer = ConfigurationManager.AppSettings["db.server"];
            string DBName = ConfigurationManager.AppSettings["db.name"];
            string DBUser = ConfigurationManager.AppSettings["db.user"];
            string DBPass = Encryption.Decrypt(ConfigurationManager.AppSettings["db.pwd"]);

            return String.Format("Data Source = {0}; Initial Catalog = {1}; User Id = {2}; Password = {3};", DBServer, DBName, DBUser, DBPass);
        }        
	}
}